﻿@model WaiGaoQiaoWeb.Models.InstockDetailedVM

@{
    ViewBag.Title = "AddInstockDetail";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    @Html.Css("dp")
    @Html.Js("datepicker")
    <script type="text/javascript" src="../../Scripts/datepicker-zh.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {

            $("#InstockDt").datepicker({ dateFormat: 'yy-mm-dd' });
            $.post('@Url.Action("RtnGoodsName","Test")', { "Id": $("#Goods_ID").val() }, function (data) {
                $("#Con_GoodsInfoGoodsName").val(data);
                $("#Con_GoodsInfoId").val($("#Goods_ID").val());
            });
            $("form").makeValidationInline();
            //自动计算金额
            $("#Price").bind("blur", function () {
                var c = $("#Count").val();
                var p = $("#Price").val();
                $("#Amount").val(c * p);
            });
            //保存
            $("#Amount").attr("readonly", true);
            //保存
            $("#btnSave").click(function (event) {
                $("#Goods_ID").val($("#Con_GoodsInfoId").val());
                $("#Goods_ID1").val($("#Con_GoodsInfoGoodsName").val());

                if (!$("#fmEdit").valid()) {
                    return false;
                }
                $('#fmEdit').ajaxSubmit(function (callback) {
                    if (callback) {
                        refresh();
                    }
                });
            }); // end of btnSave
            $("#Price").bind("change", function () {
                var price = parseFloat($("#Price").val());
                var count = parseFloat($("#Count").val());
                var mount = (price * count).toFixed(2);
                $("#Amount").val(mount);
            });
            //关闭
            $("#btnCancel").click(function (e) {
                if ($("#ID").val() != "0") {
                    CloseModelWindow(null, true);
                    return false;
                }
                if (parent) {
                    for (var i = 0; i < parent.document.frames.length; i++) {
                        if (parent.document.frames[i].document.getElementById("orderno")) {
                            parent.document.frames[i].document.getElementById("orderno").value = $("#OrderNo").val();
                        }
                    }
                    CloseModelWindow(null, true);
                }
            });
            var option = {
                height: 220,
                width: 740,
                url: '@Url.Action("GetDetailListByOrderNo")',
                colModel: [
                    { display: '编号', name: 'ID', width: 60, sortable: false, align: 'left', hide: true, iskey: true },
                    { display: '入库日期', name: 'InstockDt', width: 80, sortable: false, hide: false, align: 'left' },
			        { display: '仓库', name: 'Warehouse_ID', width: 80, sortable: false, hide: false, align: 'left' },
                    { display: '班组', name: 'Group_ID', width: 80, sortable: false, hide: false, align: 'left' },
                    { display: '食材', name: 'Goods_ID', width: 120, sortable: false, hide: false, align: 'left' },
                    { display: '数量', name: 'Count', width: 50, sortable: false, hide: false, align: 'left' },
                    { display: '单价', name: 'Price', width: 50, sortable: false, hide: false, align: 'left' },
                    { display: '金额', name: 'Amount', width: 70, sortable: false, hide: false, align: 'left' },
                    { display: '供应商', name: 'Supplier_ID', width: 120, sortable: false, hide: true, align: 'left' },
                    { display: '记录日期', name: 'RecordDateTime', width: 120, sortable: false, hide: true, align: 'left' },
                    { display: '操作人', name: 'OperatorID', width: 120, sortable: false, hide: true, align: 'left' }
				],
                singleselected: true,
                sortname: "Sequence",
                sortorder: "asc",
                title: false,
                usepager: true,
                page: 1,
                rp: 15,
                rpOptions: [10, 15],
                showcheckbox: true,
                rowbinddata: true,
                query: $("#OrderNo").val()
            };
            var grid = $("#InstockTemp").flexigrid(option);
            $("#btnDel").click(function () {
                var items = $(grid).getSelectedRows();
                if (items.length == 0) {
                    showLoadingMsg("请选择要删除的角色!", { left: 400, top: 6 }, true, 3000);
                    return false;
                }
                if (!confirm("确定要删除角色吗？")) {
                    return false;
                }
                for (var i = 0; i < items.length; i++) {
                    var id = items[i][0];
                    $.ajax({
                        type: "POST",
                        url: '@Url.Action("DeleteInstockDetail")',
                        data: { id: id },
                        dataType: "json",
                        async: false,
                        success: function (data) {
                            if (data) {
                                $("#InstockTemp").flexOptions(option).flexReload();
                            }
                        },
                        error: function () { }
                    });   // end of ajax                    
                }
            });
            function refresh() {
                showLoadingMsg("保存成功", { left: 400, top: 6 }, true, 3000);
                $("#InstockTemp").flexOptions(option).flexReload();
            }
        });
    </script>
}
@using (Html.BeginForm("SaveInstockDetail", "InstockGroup", FormMethod.Post, new { id = "fmEdit" }))
{
    @Html.ValidationSummary(true)
    <div class="mainpanel">
        @Html.HiddenFor(model => model.ID)
        @Html.HiddenFor(model => model.OrderNo)
        @Html.HiddenFor(model => model.OperatorID)
        <table style="width:100%; width:740px;">
            <tr>
                <td style="text-align:right;">@Html.LabelFor(model => model.InstockDt)</td>
                <td>@Html.TextBoxFor(model => model.InstockDt, new { @style="width:145px;",@ReadOnly = true})
                    @Html.ValidationMessageFor(model => model.InstockDt)<span style="color:Red;">*</span></td>
               <td style="text-align:right;">@Html.LabelFor(model => model.Goods_ID)</td>
                <td>
				  @Html.Partial("RtnSpoGoodsList", new Model.WaiGaoQiao.Con_GoodsInfo())
                  @Html.HiddenFor(model => model.Goods_ID)
                  @Html.HiddenFor(model => model.Goods_ID1)
			      @Html.ValidationMessageFor(model => model.Goods_ID)<span style="color:Red;">*</span></td>
            </tr>
            <tr>
                <td style="text-align:right;">@Html.LabelFor(model => model.Warehouse_ID)</td>
                <td>@Html.DropDownListFor(model => model.Warehouse_ID,
                                   ViewData["Warehouse"] as IEnumerable<SelectListItem>,
                                   new { @style = "width:152px; height:22px; font-size:13px;" })
                                <span style="color:Red;">*</span></td>
                <td style="text-align:right;">@Html.LabelFor(model => model.Count)</td>
                <td>@Html.TextBoxFor(model => model.Count)
                    @Html.ValidationMessageFor(model => model.Count)<span style="color:Red;">*</span></td>
            </tr>
            <tr>
                <td style="text-align:right;">@Html.LabelFor(model => model.Group_ID)</td>
                <td>@Html.DropDownListFor(model => model.Group_ID,
                            ViewData["Group"] as IEnumerable<SelectListItem>,
                            new { @style = "width:152px; height:22px; font-size:13px;" })
                    <span style="color:Red;">*</span></td>
                <td style="text-align:right;">@Html.LabelFor(model => model.Price)</td>
                <td>@Html.TextBoxFor(model => model.Price)
                    @Html.ValidationMessageFor(model => model.Price)<span style="color:Red;">*</span></td>
            </tr>
            <tr>
                <td style="text-align:right;">@Html.LabelFor(model => model.Supplier_ID)</td>
                <td>
					@*@Html.Partial( "RtnSupplier", new Model.WaiGaoQiao.SupplierInfo())
                    @Html.HiddenFor(model => model.Supplier_ID)*@
                    @Html.DropDownListFor(model => model.Supplier_ID,
                            ViewData["SupplierDetail"] as IEnumerable<SelectListItem>,
                            new { @style = "width:152px; height:22px; font-size:13px;" })
							 @Html.ValidationMessageFor(model => model.Supplier_ID)
			    </td>
                <td style="text-align:right;">@Html.LabelFor(model => model.Amount)</td>
                <td>@Html.TextBoxFor(model => model.Amount)
                    @Html.ValidationMessageFor(model => model.Amount)<span style="color:Red;">*</span></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td colspan="2" style="text-align:right;">
                    <a id="btnSave" class="button" href="javascript:void(0);"><span>保 存</span></a> 
                    <a id="btnDel" class="button" href="javascript:void(0);"><span>删 除</span></a>
                    <a id="btnCancel" class="button" href="javascript:void(0);"><span>关 闭</span></a>
                </td>
            </tr>
        </table>
        <div style="width:740px; overflow-x:scroll;">
            <table id="InstockTemp" style="display: none;"></table>
        </div>
    </div>
}



